﻿/**********************************************************************************
 * Project Name :   
 * Remarks      :  
 * Class Name   :  AppConfig 
 * Version      :  v1.0.0.0 
 * Author       :  Joey Liang 
 * Description  : 
 * Created Time :  2013/8/14 22:37:59
 * Update Man   :  Joey Liang
 * Update Time  :  2013/8/14 22:37:59
************************************************************************/

using JoeyLibs.Utility;
using JoeyLibs.Utility.Log;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Configuration;
using System.Linq;
using System.Text;

namespace JoeyLibs.IdleStartMenu.Model
{
    /// <summary>
    /// 程序配置文件类
    /// </summary>
    public class AppConfig
    {      
        private static AppConfig instance;
        public static AppConfig Instance
        {
            get {
                if (instance == null)
                    instance = new AppConfig();

                return instance;
            }
        }

        private string systemMenuPathKey = "SystemMenuPath";
        private string customMenuPathKey = "CustomMenuPath";
        private string menuConfigPathKey = "MenuConfigPath";
        private NameValueCollection appSettings;  

        /// <summary>
        /// 获取应用程序配置节点值
        /// </summary>
        /// <param name="key">节点键</param>
        public string this[string key] {
            get
            {
                return appSettings[key];
            } 
        }

        /// <summary>
        /// 系统进程节点路径
        /// </summary>
        public string SystemMenuPath
        {
            get { return this[systemMenuPathKey]; }
        }

        /// <summary>
        /// 用户自定义程序进程路径
        /// </summary>
        public string CustomMenuPath
        {
            get { return this[customMenuPathKey]; }
        }

        /// <summary>
        /// 进程显示菜单配置文件
        /// </summary>
        public string MenuConfigFile
        {
            get { return AppDomain.CurrentDomain.BaseDirectory + this[menuConfigPathKey]; }
        }

        //private IJoeyLog logInstance;
        ///// <summary>
        ///// 日志操作对象
        ///// </summary>
        //public IJoeyLog LogInstance
        //{
        //    get
        //    {
        //        if (logInstance == null)
        //        {
        //            if (GetSection("log4net") == null)
        //            {
        //                logInstance = UtilityFactory.CreateInstance<IJoeyLog>(AppConfig.Instance["LogAssembly"]);
        //            }

        //            if (logInstance == null)
        //            {
        //                //logInstance = new Log4netLog();
        //            }
        //        }

        //        return logInstance;
        //    }
        //}

        public bool IsShowAdvert
        {
            get { return true; }
        }

        public string AdvertBottom
        {
            get
            {
                return "<iframe width=\"300\" height=\"100\" src=\"http://www.taobao.com/go/rgn/union/aliyun_index.php?size=300x100&pid=mm_10488912_0_0\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\" border=\"0\" scrolling=\"no\" name=\"alimamaifrm\"></iframe>";
            }
        }

        private AppConfig()
        {
            this.appSettings = ConfigurationManager.AppSettings;
            
        }

        public object GetSection(string sectionName)
        {
            return ConfigurationManager.GetSection(sectionName);
        }
    }
}
